<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/5/8
  Time: 18:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<head>
    <link rel="icon" href="<c:url value="/static/images/favicon.ico"/>">
    <link rel="stylesheet" href="<c:url value="/static/lib/layui-v2.5.5/css/layui.css"/>" media="all">
    <link rel="stylesheet" href="<c:url value="/static/lib/font-awesome-4.7.0/css/font-awesome.min.css"/>" media="all">
    <link rel="stylesheet" href="<c:url value="/static/css/layuimini.css?v=2.0.1"/>" media="all">
    <link rel="stylesheet" href="<c:url value="/static/css/themes/default.css"/>" media="all">
    <link rel="stylesheet" href="<c:url value="/static/css/public.css"/>" media="all">
    <title>修改用户</title>
</head>
<div class="layuimini-main">
    <div class="layui-form layuimini-form" id="editFrom">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="nickName" id="nickName"
                       lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名"
                       value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="gender" value="1" title="男" checked="">
                <input type="radio" name="gender" value="0" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">生日</label>
            <div class="layui-input-inline">
                <input type="date" name="birthday" id="birthday"
                       lay-verify="date"  placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email" id="email"
                       lay-verify="required" placeholder="请输入邮箱" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">余额</label>
            <div class="layui-input-block">
                <input type="number" name="money" id="money"
                       lay-verify="required" placeholder="请输入余额" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="savePasBtn">确认修改</button>
            </div>
        </div>
    </div>
</div>
<script src="<c:url value="/static/lib/layui-v2.5.5/layui.js"/>" charset="utf-8"></script>
<script src="<c:url value="/static/js/lay-config.js?v=2.0.0"/>" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            // laydate = layui.laydate,
            $ = layui.$;
        var user='${userEdit}'
        user=JSON.parse(user);

        //日期
        // laydate.render({
        //     elem: '#birthday',
        //     format: 'yyyy-MM-dd',
        //     value:layui.util.toDateString(user.birthday,'yyyy-MM-dd')
        // });

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = parent.layer.getFrameIndex(window.name);

        //监听提交
        form.on('submit(savePasBtn)', function (data) {
            user.nickName=data.field.nickName;
            user.birthday=data.field.birthday;
            user.gender=data.field.gender;
            user.email=data.field.email;
            user.money=data.field.money;
            var index = layer.alert("是否确认修改该用户", {
                title: '修改信息'
            }, function () {
                $.ajax({
                    url: "/user/updateUser",
                    data: JSON.stringify(user),
                    contentType: "application/json;charset=UTF-8",
                    dataType: "json",
                    type: "POST",
                    success:function(res){
                        if(res.status===200){
                            layer.msg(res.message,{icon:1,time:1000});
                            layer.close(index);
                            // parent.layer.close(parentIndex);
                        }else{
                            layer.msg(res.message,{icon:0,time:1000});
                            layer.close(index);
                        }
                    },
                    error:function(e){
                        console.log(e,e.message);
                        alert('error');
                    }
                });
            });


            return false;
        });

    });
</script>